package com.mumu.poi.excel;

import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.FillPatternType;

import java.io.FileOutputStream;

/**
 * @author mumu
 * @version 1.0
 * @date 2024/1/8 17:12
 * @describe
 */
public class DesignGenerate {
    public static void main(String[] args) throws Exception {
        //文件路径
        String filePath = "excel/DesignGenerate.xls";
        //创建Excel文件(Workbook)
        HSSFWorkbook workbook = new HSSFWorkbook();

        HSSFSheet sheet = workbook.createSheet("Test");// 创建工作表(Sheet)
        HSSFRow row = sheet.createRow(0);

        HSSFCell cell = row.createCell(1);
        HSSFCellStyle style = workbook.createCellStyle();
        style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());//设置图案颜色
        style.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.RED.getIndex());//设置图案背景色
        style.setFillPattern(FillPatternType.SQUARES);//设置图案样式
        cell.setCellStyle(style);

        FileOutputStream out = new FileOutputStream(filePath);
        //保存Excel文件
        workbook.write(out);

        out.close();//关闭文件流
        System.out.println("OK!");

    }
}
